package com.cjack.frenchexcel.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * Created by root on 4/21/19.
 */

@ApiModel( value="公共返回体", description= "公共返回体" )
@Data
public class AppResponse<T> {
    private final static Integer DEFAULT_SUCCESS_CODE = 200;
    private final static Integer DEFAULT_ERROR_CODE = 500;
    private final static String DEFAULT_ERROR_MESSAGE = "服务器出现异常，请稍后再试";

    @ApiModelProperty( "返回code，200代表成功")
    private Integer code;
    @ApiModelProperty( "返回操作信息")
    private String message;
    @ApiModelProperty( "返回数据")
    private T data;

    public AppResponse(Integer code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public AppResponse(){

    }

    public static AppResponse RETURN(Integer code, String message, Object data){
        return new AppResponse( code, message, data);
    }

    public static AppResponse SUCCESS(Object data){
        return new AppResponse( DEFAULT_SUCCESS_CODE, null, data);
    }

    public static AppResponse SUCCESS(){
        return new AppResponse( DEFAULT_SUCCESS_CODE, null, null);
    }

    public static AppResponse ERROR(String message){
        return new AppResponse( DEFAULT_ERROR_CODE, message, null);
    }

    public static AppResponse ERROR(Integer code, String message){
        return new AppResponse( code, message, null);
    }

    public static AppResponse ERROR(){
        return new AppResponse( DEFAULT_ERROR_CODE, DEFAULT_ERROR_MESSAGE, null);
    }
}
